package collation;

import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapDemo {

    private static final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();

    /**
     * put通过桶锁/CAS 保证原子性，get通过 volatile value保证可见性
     */
    public static void main(String[] args) {
        // 并发写
        new Thread(() -> cache.put("config1", "value1")).start();
        // 并发读（无需锁）
        new Thread(() -> System.out.println(cache.get("config1"))).start();

    }

}
